<template>
  <div class="component-root-container">
    <el-header>
      <el-form ref="PTZCForm" :rules="PTZCForm" :model="queryParams" label-position="right" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="订单编号:" prop="requestId">
              <el-input v-model="queryParams['requestId']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否共享变更为:" prop="share">
              <el-select v-model="queryParams['share']" placeholder="请选择" filterable clearable>
                <el-option v-for="item in shares" :key="item.value" :label="item.key" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" class="col_button">
            <div class="button">
              <el-button class="query" @click="buttonClick">
                查询
              </el-button>
              <el-button class="query" @click="reset">
                重置
              </el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-header>
    <el-main>
      <div class="contentInfo" style="margin-bottom:20px;">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景使用情况
          </el-col>
        </el-row>
        <el-row>
          <div class="inline">
            <div><span>调用次数/日：</span><span>{{ query.count }}</span></div>
            <div><span>拦截比率：</span><span>{{ query.rate }}</span></div>
            <div><a class="link" href="javascript:;" @click="$router.push({name:'biz-ml'})">详情</a></div>
          </div>
        </el-row>
      </div>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景说明
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">集中操作审核时，判断共享场地费模式是否合规，避免场地费共享不合规影响场地费用。</div>
          </div>
          <div class="page-tip">
            <div class="params-tip"><span>示例参数</span>：订单编号：1015051100623592，是否共享变更为：是</div>
          </div>
        </el-row>
      </div>
    </el-main>

    <el-main>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            校验结果
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">
              <el-row v-for="(item,index) in dialogData" :key="index">
                <el-col>
                  订单编号: {{ item.requestId }}
                </el-col>
                <el-col>
                  结果: {{ item.returnMsg || '无' }}
                </el-col>
              </el-row>
            </div>
          </div>
        </el-row>
      </div>
    </el-main>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        dialogData: [],
        query: {
          count: 0,
          rate: '--'
        },
        queryParams: {
          requestId: '',
          share:'',
          serialNumber: '*'
        },
        shares: [{
          key: '是',
          value: '1'
        }, {
          key: '否',
          value: '0'
        }],
        PTZCForm: {
          requestId: [{
            required: true,
            message: '请输入订单编码',
            trigger: 'blur'
          }],
          share: [{
            required: true,
            message: '请选择是否共享变更为',
            trigger: 'blur,change'
          }]
        }
      }
    },
    created() {
      this.queryPageCount('2.19')
    },
    mounted() {},
    methods: {
      async buttonClick() {
        try {
          await this.$refs['PTZCForm'].validate()
          this.dialogData = []
          var params = this.queryParams;
          //console.log(params)
          const r = await this.$http({
            url: this.$http.adornBizUrl('/site/rent/sharing/verification'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify(params), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if (r.data.data.length > 0) {
            //console.log(r)
            this.dialogData = r.data.data
          }
        } catch (e) {
          console.log(e)
        } finally {

        }
      },
      reset() {
        this.queryParams = {
          requestId: '',
          serialNumber: '*',
          share: ''
        }
        this.dialogData = []
        this.$refs['PTZCForm'].clearValidate()
      },
      change(e) {
        this.$forceUpdate()
      },
      async queryPageCount(scene) {
        try {
          const r = await this.$http({
            url: this.$http.adornBizUrl('/log/queryStatistics'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify({
              scene: scene
            }), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if (r.data.data && r.data.data.length > 0) {
            var result = r.data.data[0];
            this.query.count = result.cnt || '0';
            this.query.rate = (result.per == null ? '--' : (result.per * 100).toFixed(1) + '%');
          }
        } catch (e) {
          console.log(e)
        } finally {}
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "../../../assets/scss/_formatQueryPage";
  @include formatQueryPage(0, 60%, left);
  .el-input {
    width: 60%;
  }

  .el-select {
    width: 60%;
  }

  .query {
    color: rgba(255, 255, 255, 1);
    background: rgba(235, 75, 75, 1);
    border-radius: 6px;
    border-color: rgba(235, 75, 75, 1);
  }
</style>
